package vn.edu.hut.soict.translate.wordgraph;

import java.util.ArrayList;
import java.util.List;

import vn.edu.hut.soict.translate.DefaultSentenceSplitter;

public class WordUtils {
	private static DefaultSentenceSplitter splitter;

	public static Word parseWord(String word) {
		String[] wordData = word.split("\\|");
		return new DefaultWord(wordData[0].replace('_', ' '), wordData[1]);
	}

	public static Word[] parseWordArray(String sentence) {
		List<Word> words = new ArrayList<Word>();
		String[] wordArray = sentence.split("\\s+");
		for (int i = 0; i < wordArray.length; i++) {
			words.add(parseWord(wordArray[i]));
		}
		return words.toArray(new Word[words.size()]);
	}

	public static Word[] split(String sentence) {
		if (splitter == null) {
			splitter = new DefaultSentenceSplitter();
		}
		return splitter.split(sentence);
	}

}
